package com.common.viewmodel;


import android.databinding.BaseObservable;
import android.view.View;

import com.common.manager.ViewModelListenerManager;


/**
 * @类名: BaseViewModel
 * @描述: 基础视图模式
 * @作者 cms
 * @创建日期 2017/3/6 10:20
 */
public abstract class BaseViewModel extends BaseObservable implements View.OnClickListener, View.OnLongClickListener {

    //子布局视图类型
    protected int viewType;

    public static final int ONCLICK = 1;
    public static final int LONG_CLICK = 2;
    public static final int DOUBLE_CLICK = 3;

    //监听视图模式
    protected Class<? extends ViewModelListener> viewModelListenerClazz;

    @Override
    public void onClick(View v) {
        //点击事件
        if (ViewModelListenerManager.instance().getViewModelListenerHashMap().get(viewModelListenerClazz) != null) {
            ViewModelListenerManager.instance().getViewModelListenerHashMap().get(viewModelListenerClazz).actionViewModel(v, this, ONCLICK);
        }
    }

    @Override
    public boolean onLongClick(View v) {
        //长按事件
        if (ViewModelListenerManager.instance().getViewModelListenerHashMap().get(viewModelListenerClazz) != null) {
            ViewModelListenerManager.instance().getViewModelListenerHashMap().get(viewModelListenerClazz).actionViewModel(v, this, LONG_CLICK);
        }
        return true;
    }


    public int getViewType() {
        return viewType;
    }

    public void setViewType(int viewType) {
        this.viewType = viewType;
    }


    public Class<? extends ViewModelListener> getViewModelListenerClazz() {
        return viewModelListenerClazz;
    }

    public void setViewModelListenerClazz(Class<? extends ViewModelListener> viewModelListenerClazz) {
        this.viewModelListenerClazz = viewModelListenerClazz;
    }

    public interface ViewModelListener {
        void actionViewModel(View view, BaseViewModel baseViewModel, int actionType);
    }
}
